package com.yvan.demo.proj2;

import com.google.common.collect.Maps;
import com.yvan.leto.ReloadableProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class RootController {

    @ReloadableProperty("h.a")
    private String reloadA = "";

    @Value("${h.a}")
    private String a = "";

    @Autowired
    private DemoProperties demoProperties;

    @Autowired
    private DefaultProperties defaultProperties;

    @GetMapping("/me.json")
    public Object index() {
        Map<String, Object> r = Maps.newLinkedHashMap();
        r.put("app", "proj2");
        return r;
    }

    @GetMapping("/ok")
    public String ok() {
        return "ok";
    }

    @GetMapping("/a")
    public String a() {
        return a;
    }

    @GetMapping("/reload/a")
    public String reloadA() {
        return reloadA;
    }

    @GetMapping("/properties")
    public DefaultProperties properties() {
        return defaultProperties;
    }

    @GetMapping("/reload/properties")
    public DemoProperties reloadProperties() {
        return demoProperties;
    }

}
